package com.tan.steamship.controller;

import com.tan.steamship.common.Result;
import com.tan.steamship.dto.MessageDto;
import com.tan.steamship.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: longshifu
 * @time: 2025/3/31 18:02
 */
@RestController
@RequestMapping("/message/v1")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /**
     * 保存或修改
     *
     * @param messageDto
     * @return
     */
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody MessageDto messageDto) {
        return messageService.saveOrUpdate(messageDto);
    }

    @GetMapping("list")
    public Result list(@RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex,
                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return Result.success(messageService.listAll(pageIndex,pageSize));

    }

    /**
     * 详情
     *
     * @param id id
     * @return
     */
    @GetMapping("/detail")
    public Result detail(@RequestParam("id") String id) {
        return Result.success(messageService.detail(id));
    }

    /**
     * 删除
     *
     * @param id id
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam("id") String id) {
        messageService.removeById(id);
        return Result.success();
    }

    @PostMapping("/send")
    public Result send(@RequestBody List<MessageDto> messageDtoList) {
        messageService.send(messageDtoList);
        return Result.success();
    }


}
